$(function () {
  //上方分类数据渲染

  axios
    .get("http://jx.xuzhixiang.top/ap/api/productlist.php", {
      params: { uid: 74934 },
    })
    .then(function (res) {
      console.log(res);
      var data = res.data.data;
      var data1 = data.slice(9);
      var data2 = data.slice(1, 10);
      var data3 = data.slice(3, 9);
      var data4 = data.slice(5, 11);
      let str = "";
      $(data1).each(function (i, ele) {
        str += `        
        <a href="#">
        <div class="l_p"><img src="${ele.pimg}" alt=""></div>
        <div class="l_n">${ele.pname}</div>
        </a>        
        `;
      });
      $(".l_aa").append(str);
      str = "";
      $(data).each(function (i, ele) {
        // console.log(i, ele.pimg);
        str += `        
        <a href="#">
        <div class="l_p"><img src="${ele.pimg}" alt=""></div>
        <div class="l_n">${ele.pname}</div>
        </a>        
        `;
      });
      $(".l_bb").append(str);
      str = "";
      $(data2).each(function (i, ele) {
        str += `        
        <a href="#">
        <div class="l_p"><img src="${ele.pimg}" alt=""></div>
        <div class="l_n">${ele.pname}</div>
        </a>        
        `;
      });
      $(".l_cc").append(str);
      str = "";
      $(data3).each(function (i, ele) {
        str += `        
        <a href="#">
        <div class="l_p"><img src="${ele.pimg}" alt=""></div>
        <div class="l_n">${ele.pname}</div>
        </a>        
        `;
      });
      $(".l_dd").append(str);
      str = "";
      $(data4).each(function (i, ele) {
        str += `        
        <a href="#">
        <div class="l_p"><img src="${ele.pimg}" alt=""></div>
        <div class="l_n">${ele.pname}</div>
        </a>        
        `;
      });
      $(".l_ff").append(str);
    });

  //列表项数据渲染
  axios
    .get("http://jx.xuzhixiang.top/ap/api/productlist.php", {
      params: { uid: 74651 },
    })
    .then(function (res) {
      let str = "";
      let data = res.data.data;
      data = data.slice(10);
      console.log(data);
      $(data).each(function (i, ele) {
        str += `
      <div class="innerSearch_con_li" data-id=${ele.pid}>
      <a href="#">
        <div class="pic"><img src="${ele.pimg}" alt=""></div>
        <div>
          <span class="pice"><span>￥</span>${ele.pprice}</span>
          <span class="mess">${ele.pdesc}</span>
        </div>
        <a href="#" class="pname">${ele.pname}</a>
      </a>
      <a href="#"></a>
    </div>       
           
      `;
      });
      $(".innerSearch_con").append(str);

      //进入详情页
      $(".innerSearch_con_li").on("click", function () {
        let a = $(this).attr("data-id");
        location.href = `detail.html?pid=${a}`;
      });
    });
})();
